package com.biz.primus.model.promotion.vo;

import com.biz.primus.base.exception.utils.AssertUtils;
import com.biz.primus.common.support.jackson.PrimusLocalDateTimeSerializer;
import com.biz.primus.model.promotion.exception.PromotionExceptionType;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * 降价拍降价段Vo
 *
 * @author david-liu
 */
@Getter
@Setter
public class CutPriceStairVo implements Serializable {
    private static final long serialVersionUID = 6222615695299527153L;

    /**
     * 降价时间段开始时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = PrimusLocalDateTimeSerializer.class)
    private LocalDateTime startTime;

    /**
     * 降价时间段结束时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = PrimusLocalDateTimeSerializer.class)
    private LocalDateTime endTime;

    /**
     * 销售价格
     */
    private Integer salePrice;

    public Boolean isNowInPromotionTimeRange() {
        AssertUtils.isTrue(Objects.nonNull(this.endTime) && Objects.nonNull(this.startTime) && Objects.nonNull(this.salePrice), PromotionExceptionType.ILLEGAL_STATE);
        LocalDateTime now = LocalDateTime.now();
        return startTime.isBefore(now) && endTime.isAfter(now);
    }
}
